package com.itheima.mybatis.framework;

import org.apache.ibatis.session.SqlSession;

import java.lang.reflect.Proxy;

/**
 * @author ：sean
 * @date ：Created in 2020/7/26
 * @description ：
 * @version: 1.0
 */
public class HmMapperProxyFactory<T> {

  private  Class<T> mapperInterface;

  public HmMapperProxyFactory(Class<T> mapperInterface) {
    this.mapperInterface = mapperInterface;
  }

  public Class<T> getMapperInterface() {
    return mapperInterface;
  }

  public T newInstance(HmSqlSession sqlSession) {
    final HmMapperProxy mapperProxy = new HmMapperProxy(sqlSession, mapperInterface);
    return newInstance(mapperProxy);
  }

  protected T newInstance(HmMapperProxy mapperProxy) {
    return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, mapperProxy);
  }
}
